import 'package:flutter/material.dart';
import 'package:shopping_group/entity/lz_text.dart';
import 'package:shopping_group/main/lz_mall/model/lz_mall_category_prduct_model.dart';
import 'package:shopping_group/main/lz_mall/view/lz_mall_product_page.dart';
import 'package:shopping_group/utils/route_util.dart';

import 'lz_mall_homr_product_widget.dart';

class LzMallHomeCategoryItemWidget extends StatefulWidget {
  final LzCategoryProductModel categoryProductModel;
  LzMallHomeCategoryItemWidget(this.categoryProductModel, {Key key}) : super(key: key);

  @override
  _LzMallHomeCategoryItemWidgetState createState() => _LzMallHomeCategoryItemWidgetState();
}

class _LzMallHomeCategoryItemWidgetState extends State<LzMallHomeCategoryItemWidget> {
  //header
  _buildHeaderWidget() {
    if (widget.categoryProductModel.id == "-1") {
      return Container();
    }
    return GestureDetector(
      onTap: () {
        if (widget.categoryProductModel.beMore == BeMore.N) {
          return;
        }
        RouteUtil.goParameter(LzMallProductPage(categoryProductModel: widget.categoryProductModel));
      },
      child: Container(
        color: Color(0xFFEEEEEE),
        padding: EdgeInsets.symmetric(horizontal: 16, vertical: 10),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            LzText(widget.categoryProductModel.name, color: Colors.black, fontSize: 16, fontWeight: FontWeight.w500),
            LzText(widget.categoryProductModel.beMore == BeMore.N ? "" : "查看更多",
                color: Colors.black, fontSize: 16, fontWeight: FontWeight.w500),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        color: Colors.white,
        child: Column(
          children: [
            _buildHeaderWidget(),
            GridView.builder(
              padding: EdgeInsets.zero,
              controller: ScrollController(keepScrollOffset: false), //靜止滾動事件
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 2, crossAxisSpacing: 1, mainAxisSpacing: 1, childAspectRatio: 12 / 15), //子纵比例
              shrinkWrap: true, //收缩包装
              itemBuilder: (context, index) {
                LstCommoSpec lstCommoSpec = widget.categoryProductModel.lstCommoSpec[index];
                return EcMallHomeProductWidget(lstCommoSpec);
              },
              itemCount: widget.categoryProductModel.lstCommoSpec.length,
            ),
          ],
        ));
  }
}
